/**
 *
 * @author 
 *
 */
class Page1 extends egret.Sprite{
    private _main: Main;
    
    public constructor(main: Main) 
	{
        super();
        this._main = main;
        
        //this.addEventListener(egret.TouchEvent.TOUCH_TAP, this.thisClick, this);
       
    }
    
    private touchMove(e: egret.TouchEvent): void {
        this.addEventListener(egret.TouchEvent.TOUCH_MOVE,this.thisClickMove,this);
    }
    
    private mClickNum:number= 0;
    private mSkin:Boolean;
    private m_move_y = 0;
    private mChangeing:boolean;

    private thisClickMove(e: egret.TouchEvent): void {
        if(this.mChangeing) return;
        if(this.m_move_y == 0)
            this.m_move_y = e.stageY;
        else
            if(this.m_move_y > e.stageY)
            {
                this.mChangeing  = true;
                //egret.Tween.get(this).to({ y: -100 },500);
                this._main.toPage2(this, true);
                egret.setTimeout(clean, this, 500);
                
                  function clean():void
                  {
                      this.mChangeing = false;
                  }
            }
            else
            {
                this.m_move_y = 0;
            }
    }
    
    private thisClick(e:egret.TouchEvent):void
    {
        this.mClickNum++;
        if(this.mClickNum == 1)
        {
            this.mSkin = true;
            return;
        }
        
        if(this.mClickNum >= 2)
        {
            egret.log("222");
            this._main.toPage2(this, true);
            return;
        }
    }
    
    public start():void
    {
        egret.setTimeout(this.touchMove,this,this.mSkin ? 0 : 500);
        
        var bg: eui.Image = new eui.Image;
        bg.source = "1_1_png";
        this.addChild(bg);
        
        var bg2: eui.Image = new eui.Image;
        bg2.source = "n_1_11_png";
        bg2.x = 50;
        bg2.y = 50;
        this.addChild(bg2);
        
        var bg2: eui.Image = new eui.Image;
        bg2.source = "n_arrows_png";
        bg2.x = 300;
        bg2.y = 960;
        this.addChild(bg2);
        
        egret.setTimeout(this.page2, this, this.mSkin  ? 0 : 100);
    }
    
    public page2():void
    {
        var sp: egret.Sprite = this._main.scale(this, "n_1_2_png", 456, 457, this.mSkin ? 0 : 500);
        sp.y = 400;
        sp.x = 120;
        egret.setTimeout(this.page3, this, this.mSkin ? 0 : 0);
    }
    
    public page3():void
    {
        var bg1: eui.Image = new eui.Image;
        bg1.source = "n_1_3_png";
        bg1.x = 80;
        bg1.y = 1000;
        bg1.alpha = 0;
        this.addChild(bg1);
        
        egret.Tween.get(bg1).to({
            y: 430, alpha: 1,ease: egret.Ease.bounceOut
        }, 500)
        
        this.mClickNum = 1;
    }

}
